﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Publicuse.Entity.AttributeUtil.Validate
{
    /// <summary>
    /// 最小值最大值验证
    /// </summary>
    public class MinMaxAttribute: BaseValidateAttribute
    {
        private int _iMin = 0;
        private int _iMax = 0;
        private string remark = null;
        public string GetRemark { get { return this.remark; } }

        /// <summary>
        /// 最小值  最大值
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="remark"></param>
        public MinMaxAttribute(int min, int max, string remark)
        {
            this._iMin = min;
            this._iMax = max;
            this.remark = remark;
        }

        public override bool Validate(object oValue)
        {
            if (oValue != null && !string.IsNullOrEmpty(oValue.ToString()))
            {
                var inpuvalue = oValue.ToString();
                if (Convert.ToDouble(inpuvalue) < this._iMin || Convert.ToDouble(inpuvalue) > this._iMax)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return true;
            }
           
        }
    }
}
